#! /bin/bash

# Script for Zabbix( MySQL + Nginx )

MYSQL_PASSWORD="zabbix666"
MYSQL_ROOT_PASSWORD="mysql666"


# create netword for Zabbix 
docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net

# create empty MySQL container
docker run --name zabbix-mysql -t \
           -e MYSQL_DATABASE="zabbix" \
           -e MYSQL_USER="zabbix" \
           -e MYSQL_PASSWORD="$MYSQL_PASSWORD" \
           -e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWORD" \
           --network=zabbix-net \
           --restart unless-stopped \
           -d mysql:8.0 \
           --character-set-server=utf8 --collation-server=utf8_bin \
           --default-authentication-plugin=mysql_native_password

# create Zabbix java gateway
docker run --name zabbix-java-gateway -t \
           --network=zabbix-net \
           --restart unless-stopped \
           -d zabbix/zabbix-java-gateway:alpine-5.4-latest

# create Zabbix server
docker run --name zabbix-server-mysql -t \
           -e DB_SERVER_HOST="zabbix-mysql" \
           -e MYSQL_DATABASE="zabbix" \
           -e MYSQL_USER="zabbix" \
           -e MYSQL_PASSWORD="$MYSQL_PASSWORD" \
           -e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWORD" \
           -e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
           --network=zabbix-net \
           -p 10051:10051 \
           --restart unless-stopped \
           -d zabbix/zabbix-server-mysql:alpine-5.4-latest

# create Zabbix Web
docker run --name zabbix-web-nginx-mysql -t \
           -e ZBX_SERVER_HOST="zabbix-server-mysql" \
           -e DB_SERVER_HOST="zabbix-mysql" \
           -e MYSQL_DATABASE="zabbix" \
           -e MYSQL_USER="zabbix" \
           -e MYSQL_PASSWORD="$MYSQL_PASSWORD" \
           -e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWORD" \
           --network=zabbix-net \
           -p 13352:8080 \
           --restart unless-stopped \
           -d zabbix/zabbix-web-nginx-mysql:alpine-5.4-latest
